package com.serie402.web.jsf.mb;

import org.apache.log4j.Logger;

import com.kiss.fw.jsf.mb.AbstractManagedBean;
import com.kiss.fw.utils.Util;
import com.serie402.common.bo.News;
import com.serie402.common.bo.Photo;
import com.serie402.common.dto.page.NewsPageDTO;
import com.serie402.common.utils.Constants;

public class NewsManagedBean extends AbstractManagedBean {
	private static Logger logger = Logger.getLogger(NewsManagedBean.class);
	private static News breakingNews;
	
	public News getBreakingNews() {
		// TODO: Implement a Daemon that retrieves the breaking news, should run every 10 minutes
		logger.debug("getBreakingNews");
		
		return breakingNews;
	}
	
	public String getWindowTitle() {
		return getWindowTitle(Constants.Mappings.NEWS_DTO);
	}
	
	public String getPageTitle() {
		return getPageTitle(Constants.Mappings.NEWS_DTO);
	}
	
	public NewsPageDTO getDto() {
		return (NewsPageDTO)getRequestScope().get(Constants.Mappings.NEWS_DTO);
	}
	
	public String getAuthorsDropDown() {
		return "<option value='1'>Edwin Fernandez</option><option value='2'>La LAW</option>";
	}
	
	public String getPhotoAlbumsDropDown() {
		return "<option value='1'>Album One</option><option value='2'>Album Two</option>";
	}
	
	public String getSubCategoriesViaAjax() {
		String returnVal = Util.getProperty("html.news.select.subCategory." +getRequestParam().get("category"));
		
		if(Util.isStringEmpty(returnVal)) {
			returnVal = Util.getProperty("html.news.select.subCategory");
		}
		
		return returnVal;
	}
	
	public static boolean configureBreakingNews() {
		breakingNews = new News();
		breakingNews.setNewsId(123);
		breakingNews.setPhoto(new Photo());
		breakingNews.getPhoto().setUrl("http://www.google.com/images/logos/ps_logo2.png");
		breakingNews.setTitle("Breaking News From Bean!");
		breakingNews.setDescription("This is the breaking news description from the bean!");
		
		return false;
	}
	
	public synchronized static void setBreakingNews(final News _breakingNews) {
		breakingNews = _breakingNews;
	}
}